package com.todo.common.common.entity.response;


import com.todo.common.common.entity.response.page.PageResult;
import com.todo.common.common.enums.BizEnum;
import com.todo.common.common.enums.BizErrorCodeEnum;

import java.io.Serializable;
import java.util.List;

/**
 * @author kaiwei
 * @date 2023-10-27 10:01:55
 */
public class BizPageResponse<T> implements Serializable {
    private static final long serialVersionUID = 1L;
    private int code;
    private String message;
    private PageResult<T> data;

    public BizPageResponse() {
        this(BizErrorCodeEnum.SUCCESS, BizErrorCodeEnum.SUCCESS.getDesc());
    }

    public BizPageResponse(BizEnum errorCode) {
        this(errorCode, errorCode.getDesc());
    }

    public BizPageResponse(PageResult<T> data) {
        this(BizErrorCodeEnum.SUCCESS, BizErrorCodeEnum.SUCCESS.getDesc(), data);
    }

    public BizPageResponse(List<T> list, int pageNum, int pageSize, long total) {
        this(BizErrorCodeEnum.SUCCESS, BizErrorCodeEnum.SUCCESS.getDesc(), list, pageNum, pageSize, total);
    }

    public BizPageResponse(List<T> list, int pageNum, int pageSize, long total, int currentIndex) {
        this(BizErrorCodeEnum.SUCCESS, BizErrorCodeEnum.SUCCESS.getDesc(), list, pageNum, pageSize, total, currentIndex);
    }

    public BizPageResponse(BizEnum errorCode, String message) {
        this(errorCode, message, null);
    }

    public BizPageResponse(BizEnum errorCode, String message, PageResult<T> data) {
        this.code = errorCode.getCode();
        this.message = message;
        this.data = data;
    }

    public BizPageResponse(BizEnum errorCode, String message, List<T> list, int pageNum, int pageSize, long total) {
        this.code = errorCode.getCode();
        this.message = message;
        this.data = PageResult.of(list, pageNum, pageSize, total);
    }

    public BizPageResponse(BizEnum errorCode, String message, List<T> list, int pageNum, int pageSize, long total, int currentIndex) {
        this.code = errorCode.getCode();
        this.message = message;
        this.data = PageResult.of(list, pageNum, pageSize, total, currentIndex);
    }

    public static <T> BizPageResponse<T> success() {
        return new BizPageResponse();
    }

    public static <T> BizPageResponse<T> success(String message) {
        return new BizPageResponse(BizErrorCodeEnum.SUCCESS, message);
    }

    public static <T> BizPageResponse<T> success(PageResult<T> data) {
        return new BizPageResponse(data);
    }

    public static <T> BizPageResponse<T> success(List<T> list, int pageNum, int pageSize, long total) {
        return new BizPageResponse(list, pageNum, pageSize, total);
    }

    public static <T> BizPageResponse<T> success(List<T> list, int pageNum, int pageSize, long total, int currentIndex) {
        return new BizPageResponse(list, pageNum, pageSize, total, currentIndex);
    }

    public static <T> BizPageResponse<T> success(String message, PageResult<T> data) {
        return new BizPageResponse(BizErrorCodeEnum.SUCCESS, message, data);
    }

    public static <T> BizPageResponse<T> success(String message, List<T> list, int pageNum, int pageSize, long total) {
        return new BizPageResponse(BizErrorCodeEnum.SUCCESS, message, list, pageNum, pageSize, total);
    }

    public static <T> BizPageResponse<T> success(String message, List<T> list, int pageNum, int pageSize, long total, int currentIndex) {
        return new BizPageResponse(BizErrorCodeEnum.SUCCESS, message, list, pageNum, pageSize, total, currentIndex);
    }

    public static <T> BizPageResponse<T> operationFailed() {
        return new BizPageResponse(BizErrorCodeEnum.OPERATION_FAILED);
    }

    public static <T> BizPageResponse<T> operationFailed(String message) {
        return new BizPageResponse(BizErrorCodeEnum.OPERATION_FAILED, message);
    }

    public static <T> BizPageResponse<T> systemError() {
        return new BizPageResponse(BizErrorCodeEnum.SYSTEM_ERROR);
    }

    public static <T> BizPageResponse<T> systemError(String message) {
        return new BizPageResponse(BizErrorCodeEnum.SYSTEM_ERROR, message);
    }

    public static <T> BizPageResponse<T> paramError() {
        return new BizPageResponse(BizErrorCodeEnum.PARAM_ERROR);
    }

    public static <T> BizPageResponse<T> paramError(String message) {
        return new BizPageResponse(BizErrorCodeEnum.PARAM_ERROR, message);
    }

    public int getCode() {
        return this.code;
    }

    public String getMessage() {
        return this.message;
    }

    public PageResult<T> getData() {
        return this.data;
    }

    public void setCode(final int code) {
        this.code = code;
    }

    public void setMessage(final String message) {
        this.message = message;
    }

    public void setData(final PageResult<T> data) {
        this.data = data;
    }

    public String toString() {
        return "BizPageResponse(code=" + this.getCode() + ", message=" + this.getMessage() + ", data=" + this.getData() + ")";
    }
}
